package com.crk.shixiguanli.controller;

import com.crk.shixiguanli.entity.Plan;
import com.crk.shixiguanli.entity.User;
import com.crk.shixiguanli.service.PlanService;
import com.crk.shixiguanli.util.LayUiTableJson;
import com.crk.shixiguanli.util.Page;
import com.crk.shixiguanli.util.ResponseResult;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * Description:
 *
 * @author:
 * Date: 2020-04-26
 * Time: 16:32
 */
@RestController
@RequestMapping("plan")
public class PlanController {
    @Autowired
    PlanService planService;

    /**
     * 列表页
     * @return
     */
    @RequestMapping("manage")
    public ModelAndView manage(){
        ModelAndView modelAndView = new ModelAndView("/workspace/plan/planList.html");
        return modelAndView;
    }

    @RequestMapping("show")
    public ModelAndView show(){
        User userinfo = (User) SecurityUtils.getSubject().getPrincipal();
        ModelAndView modelAndView = new ModelAndView("/workspace/plan/planShow.html");
        modelAndView.addObject("userType",userinfo.getUserType());
        return modelAndView;
    }

    /**
     * 详情页
     * @return
     */
    @GetMapping("detail")
    public ModelAndView detail(){
        ModelAndView modelAndView = new ModelAndView("/workspace/plan/planAdd.html");
        return modelAndView;
    }

    /**
     * 详情页
     * @return
     */
    @GetMapping("detailShow")
    public ModelAndView detailShow(){
        User userinfo = (User) SecurityUtils.getSubject().getPrincipal();
        ModelAndView modelAndView = new ModelAndView("/workspace/plan/planAddShow.html");
        modelAndView.addObject("userType",userinfo.getUserType());
        return modelAndView;
    }


    @GetMapping("detailStudent")
    public ModelAndView detailStudent(){
        ModelAndView modelAndView = new ModelAndView("/workspace/plan/planDetailStudent.html");
        return modelAndView;
    }

    /**
     * 详情页
     * @return
     */
    @GetMapping("myPlan")
    public ModelAndView myPlan(){
        ModelAndView modelAndView = new ModelAndView("/workspace/plan/myPlan.html");
        return modelAndView;
    }

    @GetMapping("studentComplete")
    public ModelAndView stduentComplete(){
        ModelAndView modelAndView = new ModelAndView("/workspace/plan/studentComplete.html");
        return modelAndView;
    }


    @GetMapping("statics")
    public ModelAndView statics(){
        ModelAndView modelAndView = new ModelAndView("/workspace/statics.html");
        return modelAndView;
    }



    /**
     * 分页查询
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("queryPage")
    public LayUiTableJson queryPage(@RequestParam(defaultValue = "1") int page
            , @RequestParam(defaultValue = "10") int limit){
        Page pageInfo = new Page();
        pageInfo.setCurrentPage(page);
        pageInfo.setSize(limit);
        ResponseResult ResponseResult = planService.queryPage(pageInfo);
        LayUiTableJson layUiTableJson = new LayUiTableJson(0,null,pageInfo.getAllRow(),(List)ResponseResult.getData());
        return layUiTableJson;
    }

    @GetMapping("queryStudentDetail")
    public LayUiTableJson queryStudentDetail(String planName,String studentName,@RequestParam(defaultValue = "1") int page
            , @RequestParam(defaultValue = "10") int limit){
        Page pageInfo = new Page();
        pageInfo.setCurrentPage(page);
        pageInfo.setSize(limit);
        ResponseResult ResponseResult = planService.queryStudentDetail(planName,studentName,pageInfo);
        LayUiTableJson layUiTableJson = new LayUiTableJson(0,null,pageInfo.getAllRow(),(List)ResponseResult.getData());
        return layUiTableJson;
    }

    @GetMapping("queryStudentComplete")
    public ResponseResult queryStudentComplete(@RequestParam("studentId") int studentId){
        return planService.queryStudentComplete(studentId);
    }

    @GetMapping("getStudentComplete")
    public ResponseResult getStudentComplete(@RequestParam("id") int id){
        return planService.getStudentComplete(id);
    }




    /**
     * 查询所有
     * @return
     */
    @RequestMapping("queryAll")
    public ResponseResult queryAll(){
        return planService.queryAll();
    }

    /**
     * 查询单个
     * @param id
     * @return
     */
    @RequestMapping("getOneShow")
    public ResponseResult getOneShow(@RequestParam("id") Integer id){
        return planService.getOneShow(id);
    }

    /**
     * 查询单个
     * @param id
     * @return
     */
    @RequestMapping("getOne")
    public ResponseResult getOne(@RequestParam("id") Integer id){
        return planService.getOne(id);
    }


    /**
     * 查询单个
     * @return
     */
    @RequestMapping("getMyPlan")
    public ResponseResult getMyPlan(){
        return planService.getMyPlan();
    }


    /**
     * 加入计划
     * @param id
     * @return
     */
    @RequestMapping("joinPlan")
    public ResponseResult joinPlan(@RequestParam("id") Integer id){
        return planService.joinPlan(id);
    }

    /**
     * 保存数据
     * @param job
     * @return
     */
    @RequestMapping("save")
    public ResponseResult save(Plan job){
        return planService.save(job);
    }

    /**
     * 删除数据
     * @param id
     * @return
     */
    @RequestMapping("delete")
    public ResponseResult delete(@RequestParam("id") Integer id){
        return planService.delete(id);
    }

    @RequestMapping("queryPlanList")
    public ResponseResult queryPlanList(){
        return planService.queryPlanList();
    }



    @RequestMapping("evaluate")
    public ResponseResult evaluate(@RequestParam("id") int id,@RequestParam("evaluate") String evaluate,@RequestParam("score") String score){
        return planService.evaluate(id,evaluate,score);
    }

    @RequestMapping("getCount")
    public ResponseResult getCount(){
        return planService.getCount();
    }

    @RequestMapping("getStudentProfessionalMap")
    public ResponseResult getStudentProfessionalMap(){
        return planService.getStudentProfessionalMap();
    }

    @RequestMapping("getStudentPlanMap")
    public ResponseResult getStudentPlanMap(){
        return planService.getStudentPlanMap();
    }

    @RequestMapping("getStudentJobMap")
    public ResponseResult getStudentJobMap(){
        return planService.getStudentJobMap();
    }


}
